package org.jash.demo2205.utils

import android.view.View
import android.widget.ImageView
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.google.android.material.behavior.SwipeDismissBehavior
import com.google.android.material.behavior.SwipeDismissBehavior.OnDismissListener

@BindingAdapter("image_url")
fun loadImage(image:ImageView, url:String?) {
    Glide.with(image)
        .load(url)
        .into(image)
}
@BindingAdapter("onSwipe")
fun onSwipe(view:View, listener:() -> Unit) {
    (view.layoutParams as? CoordinatorLayout.LayoutParams)?.let {
        it.behavior = SwipeDismissBehavior<View>().apply {
            this.listener = object : OnDismissListener {
                override fun onDismiss(view: View?) {
                    listener()
                    view?.alpha = 1f
                }
                override fun onDragStateChanged(state: Int) {
                }

            }
        }
    }
}
